package com.wakala.employment.fragment.other;

import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.just.agentweb.core.AgentWeb;
import com.leaf.library.StatusBarUtil;
import com.wakala.employment.R;
import com.wakala.employment.core.BaseFragment;
import com.wakala.employment.core.webview.BaseWebViewFragment;
import com.wakala.employment.databinding.FragmentUserIntegralBinding;
import com.wakala.employment.utils.Utils;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.enums.CoreAnim;
import com.xuexiang.xui.utils.XToastUtils;
import com.xuexiang.xui.widget.actionbar.TitleBar;

/**
 * A simple {@link Fragment} subclass.O
 * Use the {@link UserIntegralFragment#} factory method to
 * create an instance of this fragment.
 */
@Page(anim = CoreAnim.none)
public class UserIntegralFragment extends BaseWebViewFragment<FragmentUserIntegralBinding> implements View.OnClickListener {

    private Handler mHandler = new Handler(Looper.getMainLooper());


    @NonNull
    @Override
    protected FragmentUserIntegralBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) {
        return FragmentUserIntegralBinding.inflate(inflater, container, attachToRoot);
    }

    @Override
    protected TitleBar initTitle() {
        TitleBar titleBar = super.initTitle();
        titleBar.setTitle("我的积分");
        titleBar.setTitleColor(R.color.white);
        titleBar.setLeftTextColor(R.color.white);
        titleBar.setLeftImageDrawable(getResources().getDrawable(R.drawable.icon_arrow_white));
        titleBar.setBackgroundResource(R.color.colorBgKingYellow);//设置标题栏背景
        //StatusBarUtil.setLightMode(getActivity());
        //设置状态栏背景颜色，如果设置为 Color.TRANSPARENT 将会隐藏状态栏
        getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.colorBgKingYellow));
        return titleBar;
    }

    @Override
    protected void initViews() {
        mAgentWeb = Utils.createAgentWeb(this, binding.container, "file:///android_asset/userIntegral.html");
        mAgentWeb.getJsInterfaceHolder().addJavaObject("Android", new AndroidInterface());
    }

    @Override
    public void onClick(View view) {

    }

    public  class AndroidInterface {

        @JavascriptInterface
        public void callAndroid(final String msg) {
            XToastUtils.toast("这是Js调用Android的方法，内容:" + msg);
        }
        @JavascriptInterface
        public void  toRecord(){
            openNewPage(UserIntegralRecordFragment.class);
        }

    }
}